package com.itheima.sqlSession;

import com.itheima.config.XMLConfigBuilder;
import com.itheima.pojo.Configuration;
import org.dom4j.DocumentException;

import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    /**
     * 解析配置文件 封装容器对象
     * 创建SqlSessionFactory对象
     * @param inputStream
     * @return
     */
    public SqlSessionFactory build(InputStream inputStream) throws DocumentException {
        //1.解析配置文件,封装容器对象
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration=xmlConfigBuilder.parse(inputStream);
        //2.创建sqlSessionFactory工厂对象
        SqlSessionFactory sqlSessionFactory=new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }

}
